import numpy as np
import pandas as pd
from package_ternary_calculation import thermodynamic
from package_ternary_calculation import kinetic

thermodynamic_database = "TCNI10"
kinetic_database = "MOBNI5"

elements = ["Ni", "Al", "Cr"]  # 0,1,2 namely A,B,C
phases = {'DIS_FCC_A1': 0, 'FCC_L12': 1, 'BCC_A2': 0, 'BCC_B2': 1}
target_phase = 'FCC_L12'
temp = 1473

B_diff_pot_range = np.linspace(-1e5, 1e5, 500)
C_diff_pot_range = np.linspace(-1e5, 1e5, 500)

# thermodynamicfile = "Thermodynamic_%s_%s_%s_%s_%.2fK_Raw.csv" % (
#        elements[0], elements[1], elements[2], target_phase, temp)
thermodynamicfile = thermodynamic(elements, target_phase, thermodynamic_database,
                                  temp, B_diff_pot_range, C_diff_pot_range, phases[target_phase])
TF_pd_reader = pd.read_csv(
    thermodynamicfile, header=0, sep=',').interpolate()  # handle NaNs with pandas
TF_pd_reader.to_csv('pd_'+thermodynamicfile, index=0, sep=',')
x_B_ = TF_pd_reader['x_'+elements[1]+'_'+target_phase]
x_C_ = TF_pd_reader['x_'+elements[2]+'_'+target_phase]
#kineticfile = "Kinetic_%s_%s_%s_%s_%.2fK_Raw.csv" % (
#        elements[0], elements[1], elements[2], target_phase, temp)
kineticfile = kinetic(elements, target_phase, thermodynamic_database, kinetic_database,
                      temp, B_diff_pot_range, C_diff_pot_range, x_B_, x_C_, phases[target_phase])
LB_pd_reader = pd.read_csv(
    kineticfile, header=0, sep=',').interpolate()  # handle NaNs with pandas
LB_pd_reader.to_csv('pd_'+kineticfile, index=0, sep=',')
